#include <iostream>
#include <string>
using namespace std;

// 组合 Logger 组合 LogFac

class LogOutput
{
private:
public:
    // 日志输出
    virtual void Output(const string &log) = 0;

    LogOutput() {}
    ~LogOutput() {}
};

class LogConsoleOutput : public LogOutput
{
private:
public:
    LogConsoleOutput() {}
    ~LogConsoleOutput() {}

    void Output(const string &log) override
    {
        cout << log << endl;
    };
};

class Logger
{
private:
    LogOutput *output_{nullptr};

public:
    Logger() { cout << "Create Logger" << endl; }
    ~Logger()
    {
        delete output_;
        output_ = nullptr;
        cout << "Drop Logger" << endl;
    }

    void Write(const string &log) { output_->Output(log); };

    void SetOutput(LogOutput *out) { output_ = out; };
};

class LogFac // 日志工程 单件模式
{
private:
    Logger logger_;
    LogFac()
    {
        logger_.SetOutput(new LogConsoleOutput);
        cout << "Create LogFac" << endl;
    }

public:
    static LogFac &Instance()
    {
        static LogFac fac;
        return fac;
    }

    ~LogFac() { cout << "Drop LogFac" << endl; }
};

int main(int argc, char const *argv[])
{
    Logger logger;
    logger.SetOutput(new LogConsoleOutput);

    logger.Write("test console log");

    // LogFac logfac;
    LogFac::Instance();

    return 0;
}
